<!-- 题目名称 -->
<template>
  <el-form-item prop="name" label="题目名称：" :rules="nameRequiredRule">
    <el-input
      v-model="formStore.selectQuestion.name"
      clearable
      @blur="handleBlur"
      maxlength="50"
      @keyup.enter.native="handleBlur"
    />
  </el-form-item>
</template>

<script lang="ts" setup>
import { useFormStore } from "@bis/stores/form";
import { editQue } from "../../../utils";

const formStore = useFormStore();
const oldName = formStore.selectQuestion.name;

const nameRequiredRule = [{ required: true, message: "数据元不可为空" }];

const handleBlur = () => {
  if (formStore.selectQuestion.name === "") {
    formStore.selectQuestion.name = oldName;
  }
  if (formStore.selectQuestion.name !== oldName) {
    // 调用保存
    editQue(formStore.selectQuestion, formStore);
  }
};
</script>
